﻿
//依赖项同lockin
#pragma once
#include "../common/serialport.h"
#include "../common/motor_head.h"

serialPort com;
static bool xAxis=true;

//dll入口
BOOL APIENTRY DllMain( HANDLE hModule,
	DWORD  ul_reason_for_call, 
	LPVOID lpReserved
	)
{
	switch( ul_reason_for_call )
	{
	case DLL_PROCESS_ATTACH:break;
	case DLL_THREAD_ATTACH:break;
	case DLL_THREAD_DETACH:break;
	case DLL_PROCESS_DETACH:
		com.CloseCom();
	}
	return TRUE;
}

//
void selAxis(bool x)
{
	xAxis=x;
}

bool f() 
{
	char strr[5];
	sprintf(strr,"+%c 1\r",xAxis?'X':'Y');
	return com.WriteCom(strr);
}
bool b() 
{
	char strr[5];
	sprintf(strr,"-%c 1\r",xAxis?'X':'Y');
	return com.WriteCom(strr);
}
bool setdivide(int d) 
{
	/*char cmd[4]="";
	sprintf(cmd,"D%d",d);
	return com.WriteCom(cmd);*/
	return true;
}

void fastSteps(unsigned int steps,bool forward) 
{
	char strr[10];
	sprintf(strr,"%c%c %d\r",forward?'+':'-', xAxis?'X':'Y' ,steps);
	com.WriteCom(strr);
	Sleep(int(steps*.5));//10000步，一般5000ms内
}

extern "C" __declspec(dllexport) void setupMotorEngine(motorInterface& dest)
{
	dest.openCom=openCom;
	dest.closeCom=closeCom;

	dest.setDivide=setdivide;
	dest.forward=f;
	dest.backword=b;
	dest.fastSteps=fastSteps;
	dest.selAxis=selAxis;
}





